﻿package br.com.wssa.email.ejb.service.impl;

import java.util.logging.Logger;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

import br.com.wssa.email.dto.EmailDTO;
import br.com.wssa.email.util.EmailUtil;

/**
 * EmailConsumerService.
 */
@MessageDriven(name = "EmailConsumerService", mappedName = "jms/queue/EmailQueue", activationConfig = {
		@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
		@ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
		@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
		@ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/queue/EmailQueue") })
public class EmailConsumerService implements MessageListener {

	public static final Logger LOGGER = Logger.getLogger(EmailConsumerService.class.getName());

	/**
	 * onMessage
	 */
	public void onMessage(final Message message) {
		try {
			LOGGER.info("onMessage inicio");
			final ObjectMessage objetctMessage = (ObjectMessage) message;
			final EmailDTO EmailDTO = (EmailDTO) objetctMessage.getObject();
			EmailUtil.enviarEmail(EmailDTO);

			LOGGER.info("onMessage fim");
		} catch (Exception e) {
			LOGGER.info(e.getMessage() + e);
			//throw new SystemException(e);
		}
	}
}